<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>user-add</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
        <link rel="stylesheet" href="{*cdn*}css/font.css">
        <link rel="stylesheet" href="{*cdn*}css/xadmin.css">
        <script type="text/javascript" src="{*cdn*}lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="{*cdn*}js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="name" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.name']*}
                      </label>
                      <div class="layui-input-inline">
                          <input id="name" type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.name.notice']*}
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="url" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.url']*}
                      </label>
                      <div class="layui-input-inline">
                          <input id="url" type="text" name="url" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.url.notice']*}
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="icon" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.icon']*}
                      </label>
                      <div class="layui-input-inline">
                          <input id="icon" type="text" name="icon" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>{*locale['dashboard.menu.menu_manage.menu_edit.form.icon.notice']*}
                          <i title="{*locale['dashboard.menu.menu_manage.menu_add.form.icon.help']*}" class="layui-icon layui-icon-tips" onclick="window.open('https://www.layui.com/doc/element/icon.html')"></i>
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="action" value="edit">
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="id" value="{*id*}">
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="token" value="{*token*}">
                      </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <button id="submit" class="layui-btn" lay-filter="edit" lay-submit="">{*locale['dashboard.menu.menu_manage.menu_edit.form.submit']*}</button>
                  </div>
              </form>
            </div>
        </div>
        <script>
        layui.use(['jquery', 'form', 'layer'], function() {
          $ = layui.jquery;
          var form  = layui.form;
          var layer = layui.layer;
          //监听提交
          form.on('submit(edit)', function(data) {
            if (!$('#submit').is(":hidden")) {
              $('#submit').hide();
              $.ajax({
                url: "{*api_url*}", type: "POST", headers: {token:"{*token*}"}, data: data.field,
                error: function (res) {
                  return layer.msg('请求失败', {time:2000}, function () {
                    $('#submit').show();
                  });
                },
                success: function (res) {
                  if (res.code != 0) {
                    return layer.msg(res.msg, {time:2000}, function () {
                      $('#submit').show();
                    });
                  }
                  return layer.msg(res.msg, {time:1000}, function () {
                    xadmin.close();
                    xadmin.father_reload();
                  });
                },
              });
            }
            return false;
          });

        });
        // 直接渲染value会导致被转义;
        document.getElementById('name').value = '{*menu.name*}';
        document.getElementById('url').value = "{*menu.url ~= null and menu.url or '' *}";
        document.getElementById('icon').value = '{*menu.icon*}';
      </script>
    </body>

</html>
